package com.controller;

import com.model._do.AppointmentDO;
import com.model._do.DoctorAuthDO;
import com.model.dto.SignedRelateDTO;
import com.model.dto.SuperviseDTO.*;
import com.model.dto.SuperviseDTO.Search.*;
import com.model.dto.baseDTO.ResultDTO;
import com.service.*;
import com.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/supervise")
public class SuperviseController {

    @Autowired
    private UserService userService;

    @Autowired
    private DoctorAuthService doctorAuthService;

    @Autowired
    private ResultService resultService;

    @Autowired
    private AppointmentService appointmentService;

    @Autowired
    private EquipmentService equipmentService;

    @RequestMapping("/getAuthInfo")
    public ResultDTO getAuthInfo(@RequestBody AuthDoctorSearch search){
        if(search.getUserId() != null && search.getUserId().length() <= 0){
            search.setUserId(null);
        }
        List<AuthDoctorDTO> dtoList = doctorAuthService.getAuthInfo(search);
        return resultService.createSuccess("success",new PageDTO(PageUtil.getPageList(search.getPageSize(), search.getPageIndex(),dtoList),dtoList.size()));
    }

    @RequestMapping(value = "/pushAuthResult", method = RequestMethod.POST)
    public ResultDTO pushAuthResult(@RequestBody DoctorAuthDO auth){
        try{
            doctorAuthService.pushAuthResult(auth);
            return resultService.createSuccess();
        }catch (Exception e){
            return resultService.createFailed();
        }
    }

    @RequestMapping(value = "/getUserInfo")
    public ResultDTO getUserInfo(@RequestBody UserInfoSearch search){
        try{
            List<UserInfoDTO> userList = userService.getUserByType(search);
            return resultService.createSuccess("success",new PageDTO(PageUtil.getPageList(search.getPageSize(), search.getPageIndex(),userList), userList.size()));
        }catch (Exception e){
            return resultService.createFailed();
        }
    }

    @RequestMapping(value = "/getAppointInfo")
    public ResultDTO getAppointInfo(@RequestBody AppointSearch search){
        try{
            List<AppointInfo> appointList = appointmentService.getAppointInfo(search);
            return resultService.createSuccess("success", new PageDTO(PageUtil.getPageList(search.getPageSize(), search.getPageIndex(),appointList),appointList.size()));
        }catch (Exception e){
            return resultService.createFailed();
        }
    }

    @RequestMapping(value = "/getEquipInfo")
    public ResultDTO getEquipInfo(@RequestBody EquipSearch search){
        List<EquipSignDTO> equipList = equipmentService.getEquipInfo(search);
        return resultService.createSuccess("success", new PageDTO(PageUtil.getPageList(search.getPageSize(), search.getPageIndex(),equipList), equipList.size()));
    }

    @RequestMapping(value = "/getAppointPie")
    public ResultDTO getAppointPie(){
        return resultService.createSuccess("success", appointmentService.getPie());
    }
}
